package org.example.admin.exception;

import org.example.admin.exception.exceptions.KaptchaExpiredException;
import org.example.admin.exception.exceptions.KaptchaVerifyException;
import org.example.common.constant.ResponseCode;
import org.example.common.utils.ResponseUtil;
import org.example.security.exception.SecurityAuthException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class AdminExceptionHandler {

     @ExceptionHandler(KaptchaVerifyException.class)
     public Object kaptchaVerifyException(KaptchaVerifyException e){
          return ResponseUtil.fail(ResponseCode.KAPTCHA_ERROR, "验证码错误");
     }

     @ExceptionHandler(KaptchaExpiredException.class)
     public Object kaptchaExpiredException(KaptchaExpiredException e){
          return ResponseUtil.fail(ResponseCode.KAPTCHA_EXPIRED, "验证码过期");
     }

     @ExceptionHandler(SecurityAuthException.class)
     public Object securityAuth(SecurityAuthException e){
          return ResponseUtil.fail(ResponseCode.USERNAME_OR_PASSWORD_ERR, "用户名或密码错误");
     }
}
